package com.asia5b.a5mall.order.adapter

import android.view.View
import android.widget.ImageView
import com.asia5b.a5mall.middleware.model.order.OrderDetailModel
import com.asia5b.a5mall.middleware.model.bean.OrderListType
import com.asia5b.a5mall.middleware.model.order.ParcelModel
import com.asia5b.a5mall.order.R
import com.asia5b.a5mall.order.widget.OrderGoodsView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/3/9.
 */
class OrderListParcelAdapter(var orderDetailModel: OrderDetailModel, var list: ArrayList<ParcelModel>) :
        BaseQuickAdapter<ParcelModel, BaseViewHolder>(R.layout.item_orderlist_parcelitem_adapter, list) {
    init {
        addChildClickViewIds(R.id.iv_orderlist_goodscheck)
    }
    override fun convert(helper: BaseViewHolder, item: ParcelModel) {
        val ll_orde_goodslist = helper.getView<OrderGoodsView>(R.id.ll_orde_goodslist)
        val view_order_divider = helper.getView<View>(R.id.view_order_divider)
        ll_orde_goodslist.setGoodsList(orderDetailModel, OrderListType.APPLY_PACKAGING, item.goods_list, item.total_weight)
        val iv_orderlist_goodscheck = ll_orde_goodslist.findViewById<ImageView>(R.id.iv_orderlist_goodscheck)
        iv_orderlist_goodscheck.visibility = View.VISIBLE
        if (item.isCanParcel) {//是否能申请打包
            iv_orderlist_goodscheck.isSelected = item.checked
        } else {
            iv_orderlist_goodscheck.setImageResource(R.drawable.ic_orderlist_uncheck)
        }
        if (helper.layoutPosition == (list.size - 1)) {
            view_order_divider.visibility = View.GONE
        } else {
            view_order_divider.visibility = View.VISIBLE
        }
    }
}